import numpy as np

img_arr = np.array([
    [1, 2, 3, 4],
    [5, 6, 7, 8],
    [9, 10, 11, 12],
    [13, 14, 15, 16]
], dtype="f4")

# 1. 进行填充
img_fill_arr = np.array([
    [6, 5, 6, 7, 8, 7],
    [2, 1, 2, 3, 4, 3],
    [6, 5, 6, 7, 8, 7],
    [10, 9, 10, 11, 12, 11],
    [14, 13, 14, 15, 16, 15],
    [10, 9, 10, 11, 12, 11]
])

# 2. 特定大小的均值滤波核
mean_kernel = np.array([
    [1/9, 1/9, 1/9],
    [1/9, 1/9, 1/9],
    [1/9, 1/9, 1/9]
])

# 3. 在填充好的图像上进行不断滑动计算
for i in range(4):
    for j in range(4):
        t = (img_fill_arr[i:i + 3, j:j + 3] * mean_kernel).sum()
        img_arr[i, j] = t
print(img_arr)